package servlet.stu;

import bean.Result;
import bean.Student;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.UserDaoImpl;
import utils.JwtUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


//获取学生信息
@WebServlet("/stu/getStuInfo")
public class GetStuInfoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String user_token = request.getHeader("user_token_header");
        Integer stuId = JwtUtils.getStuIdFromToken(user_token,"stuId");
        Student student = new UserDaoImpl().findById(stuId);
        Result result = new Result();
        result.success(student);
        ObjectMapper objectMapper = new ObjectMapper();
        String str = objectMapper.writeValueAsString(result);
        response.setContentType("application/json;charset=utf8");
        response.getWriter().print(str);

    }
}
